import { defineConfig } from 'vite'

import path from "path";
import runVitePlugins from "./viteConfig";

// https://vitejs.dev/config/
export default defineConfig(({command})=>{
  const isBuild = command == 'build';
  return {
    plugins: runVitePlugins(),
    base:isBuild ? '/my' : '/',
    //别名
    resolve:{
      alias:{'@':path.resolve(__dirname,'src')}
    },
    build: {
      //编译文件生成目录
     // outDir: '../dist',
      emptyOutDir: true,
      rollupOptions: {
        output: {
          manualChunks(id: string) {
            if (id.includes('node_modules')) {
              return id.split('/node_modules/').pop()?.split('/')[0]
            }
          },
        },
      },
    },
    server: {
      host: true,
      proxy: {
        '/api': {
          target: 'http://bk.test',
          changeOrigin: true,
        },
        '/captcha': {
          target: 'http://bk.test',
          changeOrigin: true,
        },
      },

    },
  }
})
